package org.zhb.sql.query.core.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class LoginInterceptor extends HandlerInterceptorAdapter {
	@Override
	public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
		// 使用shiro 判断用户是否登陆
		Subject subject = SecurityUtils.getSubject();
		// 跳转到登陆页面
		if (!subject.isAuthenticated()) {
			response.sendRedirect(request.getContextPath() + "/index");
			// 没有登陆
			return false;
		}
		return true;
	}
}
